#include "qlogger.h"

QLogger* QLogger::m_instance = NULL;
quint8 QLogger::m_level = 0;

QLogger::QLogger(quint8 lvl)
{
	m_level = lvl;
}

QLogger::~QLogger()
{

}

QLogger* QLogger::instance(quint8 lvl)
{
	if(!m_instance)
		m_instance = new QLogger(lvl);
	return m_instance;
}

void QLogger::destroy()
{
	delete m_instance;
	m_instance = NULL;
}

void QLogger::trace(QString text,quint8 lvl)
{
	if(lvl >= m_level)
	{
		QFile file(LOG_FILE);
		if(file.open(QIODevice::ReadWrite|QIODevice::Append|QIODevice::Text))
		{
			QTextStream stream(&file);
			stream << format(text);
		}
	}

}


QString QLogger::format(QString text)
{
	QString date = QDateTime::currentDateTime().toString("ddMMyyyy hh:mm:ss:zzz");
	return date + "\t" + __FILE__  + "\t" + __LINE__ + "\t" + text + "\n";
}